﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Monitoring.aspx.cs" Inherits="ControlYSeguimiento_Web_App.Monitoring.Monitoring" %>

<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManagerRefresh" runat="server">
    </asp:ScriptManager>
    <div class="MapControlsBox">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td>
                    <asp:Button ID="btnLogOut" Text="Logout" runat="server" CssClass="LoginButton" OnClick="btnLogOut_Click" />
                    <asp:Button ID="btnChangeValues" Text="My account" runat="server" CssClass="LoginButton"
                        PostBackUrl="~/Monitoring/UserInfo/UserInfoDetails.aspx" />
                </td>
                <td align="right">
                    <asp:Label ID="Label4" Text="Refresh Map Time" runat="server" />                   
                    <asp:DropDownList ID="DdlLanguage" Width="127px" AutoPostBack="true" OnSelectedIndexChanged="DdlLanguage_SelectedIndexChanged"
                        runat="server">                        
                        <asp:ListItem Text="30s" Selected="True" Value="30000" />
                        <asp:ListItem Text="45s" Value="45000" />
                        <asp:ListItem Text="60s" Value="60000" />
                        <asp:ListItem Text="90s" Value="90000" />
                    </asp:DropDownList>
                  
                </td>
            </tr>
        </table>
    </div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerRefresh" EventName="Tick" />
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
            <asp:PostBackTrigger ControlID="GridViewDetails"></asp:PostBackTrigger>
        </Triggers>
        <ContentTemplate>
            <asp:Panel ID="PanelDetail" runat="server" Visible="false" CssClass="PanelDetails">
                <asp:Label ID="LabelSelectedTarget" Text="User:" CssClass="GreenMessage" runat="server" />
                <asp:GridView ID="GridViewDetails" runat="server" CssClass="TargetGrid" DataSourceID="ObjectDataSourceTarget"
                    AutoGenerateColumns="False" DataKeyNames="CurrentDeviceId,Id" OnRowUpdating="GridViewDetails_RowUpdating">
                    <Columns>
                        <asp:TemplateField HeaderText="Mobile - User ID" SortExpression="CurrentImei">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBoxEditImei" MaxLength="22" runat="server" Text='<%# Bind("CurrentImei") %>'></asp:TextBox>
                                <asp:HiddenField ID="HiddenImei" Value='<%# Bind("CurrentImei") %>' runat="server"
                                    Visible="false" />
                                <br />
                                <asp:CustomValidator ID="CustomValidatorEditImei" CssClass="failureNotification"
                                    ControlToValidate="TextBoxEditImei" Display="Dynamic" runat="server" ErrorMessage="This User Id already exists."
                                    OnServerValidate="CustomValidatorEditImei_ServerValidate"></asp:CustomValidator>
                                <asp:RequiredFieldValidator ID="RequireFieldValidatorEditImei" CssClass="failureNotification"
                                    ControlToValidate="TextBoxEditImei" ErrorMessage="This field can't be empty"
                                    Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("CurrentImei") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Code" SortExpression="CurrentCode">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBoxEditCode" runat="server" MaxLength="10" Text='<%# Bind("CurrentCode") %>'></asp:TextBox><br />
                                <asp:RequiredFieldValidator ID="RequireFieldValidatorEditCode" CssClass="failureNotification"
                                    ControlToValidate="TextBoxEditCode" ErrorMessage="This field can't be empty"
                                    Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("CurrentCode") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Picture" SortExpression="Picture">
                            <EditItemTemplate>
                                <asp:FileUpload ID="FileUploadPicture" runat="server" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Image runat="server" ID="ImagePicture" ImageUrl='<%# Eval("Picture") %>' ImageAlign="Middle"
                                    Height="48px" Width="48px" /><br />
                            </ItemTemplate>
                            <ControlStyle Width="100px" />
                            <FooterStyle Width="100px" />
                            <HeaderStyle Width="100px" />
                            <ItemStyle Width="100px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="CurrentDeviceId" HeaderText="CurrentDeviceId" SortExpression="CurrentDeviceId"
                            Visible="False" />
                        <asp:CommandField ShowEditButton="True" />
                        <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="False" />
                    </Columns>
                </asp:GridView>
                <asp:Button ID="ButtonReady" CssClass="LoginButton" Text="Ready" PostBackUrl="Monitoring.aspx"
                    runat="server" />
            </asp:Panel>
            <table class="tableAllWide" border="0" cellpadding="1" cellspacing="1">
                <tr>
                    <td class="cellAtLeft300px">
                        <asp:GridView ID="GridViewTargets" CssClass="TargetGrid" runat="server" EmptyDataText="There aren't targets set up for your account."
                            DataKeyNames="Id" AutoGenerateColumns="False" DataSourceID="ObjectDataSourceTargets"
                            AllowPaging="True" OnRowUpdating="GridViewTargets_RowUpdating" OnRowCommand="GridViewTargets_RowCommand"
                            OnRowUpdated="GridViewTargets_RowUpdated">
                            <Columns>
                                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" Visible="False" />
                                <asp:TemplateField HeaderText="Target" SortExpression="Name">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:HyperLink ID="HyperLinkName" runat="server" Text='<%# Bind("Name") %>' NavigateUrl='<%# "Monitoring.aspx?id="+Eval("Id") %>'></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Battery Level" SortExpression="CurrentBatteryLevel">
                                    <EditItemTemplate>
                                        <asp:Label ID="lblEditBatteryLevel" Text='<%# Bind("CurrentBatteryLevel") %>' runat="server" />
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("CurrentBatteryLevel") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="CurrentSpeed" HeaderText="Speed" SortExpression="CurrentSpeed"
                                    ReadOnly="True" />
                                <asp:TemplateField HeaderText="Position" SortExpression="CurrentCooridinate">
                                    <EditItemTemplate>
                                        <asp:Label ID="lblEditCoordinate" Text='<%# Bind("CurrentCooridinate") %>' runat="server" />
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("CurrentCooridinate") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Show" SortExpression="ShowInMap">
                                    <EditItemTemplate>
                                        <asp:CheckBox ID="CheckBoxVerEnMapaEditar" runat="server" Text="" Checked='<%# Bind("ShowInMap") %>' />
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="CheckBoxVerEnMapa" runat="server" Text="" Enabled="false" Checked='<%# Bind("ShowInMap") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Watch in Map">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="ImageButtonCentrarEnMapa" runat="server" CausesValidation="False"
                                            CommandName="CentrarEnMapa" Text="Ver en Mapa" CommandArgument='<%# Eval("Id") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Show Trace">
                                    <ItemTemplate>
                                        <asp:Label ID="lblVerTrayectoria" Text='<%# Eval("TraceTimeSpan")+" minutes" %>'
                                            runat="server" />
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="DropDownListTrayectoria" runat="server" Width="87px" SelectedValue='<%# Bind("TraceTimeSpan") %>'>
                                            <asp:ListItem Value="5">Last 5 min</asp:ListItem>
                                            <asp:ListItem Value="10">Last 10 min</asp:ListItem>
                                            <asp:ListItem Value="30">Last 30 min</asp:ListItem>
                                            <asp:ListItem Value="60">Last hour</asp:ListItem>
                                            <asp:ListItem Value="360">Last 6 hours</asp:ListItem>
                                            <asp:ListItem Value="1440">Last 24 hours</asp:ListItem>
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:CommandField EditText="Edit" ShowEditButton="True" />
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
                <tr class="tableTop">
                    <td>
                        <cc1:GMap ID="GMap1" runat="server" enablePostBackPersistence="True" Height="600px"
                            OnMoveEnd="GMap1_MoveEnd" OnServerEvent="GMap1_ServerEvent" serverEventsType="AspNetPostBack"
                            Width="100%" />
                    </td>
                </tr>
            </table>
            <asp:ObjectDataSource ID="ObjectDataSourceTargets" runat="server" OldValuesParameterFormatString="original_{0}"
                OnObjectCreating="ObjectDataSourceTargets_ObjectCreating" SelectMethod="GetTargetsFromCustomersUsername"
                TypeName="ControlYSeguimiento.Domain.Facade" OnSelecting="ObjectDataSourceTargets_Selecting"
                UpdateMethod="SaveTarget" DataObjectTypeName="ControlYSeguimiento.Domain.Target">
                <SelectParameters>
                    <asp:Parameter DefaultValue=" " Name="userNameParam" Type="String" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:ObjectDataSource ID="ObjectDataSourceTarget" runat="server" OldValuesParameterFormatString="original_{0}"
                OnObjectCreating="ObjectDataSourceTargets_ObjectCreating" SelectMethod="GetTargetById"
                TypeName="ControlYSeguimiento.Domain.Facade" OnSelecting="ObjectDataSourceTarget_Selecting"
                OnUpdating="ObjectDataSourceTarget_Updating" DataObjectTypeName="ControlYSeguimiento.Domain.Target"
                UpdateMethod="SaveTarget">
                <SelectParameters>
                    <asp:Parameter Name="idParam" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="GridViewDetails" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Timer ID="TimerRefresh" runat="server" Interval="30000" OnTick="TimerRefresh_Tick">
    </asp:Timer>
</asp:Content>
